<?
require("config/config.php");
require("lib/lib.mysql.php");
require("lib/lib.common.php");
require("lib/lib.htdb.php");

$db = new db;
$db->connect($db_host, $db_user, $db_pass, $db_name);
$common = new common;
$session = new session($common,$db);

$action = $_GET["action"];
$username = $_POST["username"];
$password = $_POST["password"];

if(empty($action))
  $action = "logout";

switch ($action) {
case "login":

   $return = $session->login($username,$password,$common,$db);
	$template = "";
   if($return) {
   	 $user_id = $_SESSION["uid"];
   	 $common->redirect("cms_main.php");
   } else {
     $template = "templates/cms_login.htm";
   }
   break;
case "logout":
   $session->logout();
   $template = "templates/cms_login.htm";
   break;
}

ob_start();
require($template);
$output = ob_get_contents();
ob_end_clean();

print $output;

$db->close();
?>